package dynamic_handle;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;

import DB.DB_connection_pool;


public class Delete_leaving_user_msg extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String delete_leaving_user_account = request.getParameter("delete_leaving_user_account");
		String user_account = request.getSession().getAttribute("user_account").toString();
		
		String delete_sql = "delete from leaving_messages where send_leaving_messages = '"+delete_leaving_user_account+"' and receive_leaving_messages = '"+user_account+"'";
		JSONObject jsonObj = new JSONObject();
		
		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement ps_delete = conn.prepareStatement(delete_sql);
			ps_delete.executeUpdate();
			
			ps_delete.close();
			conn.close();
			
			jsonObj.put("result", true);
		} catch (SQLException e) {
			jsonObj.put("result", false);
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		out.print(jsonObj.toString());
	}

}
